package com.crocodileQ.utils;

import org.springframework.beans.BeanUtils;

import java.util.List;
import java.util.stream.Collectors;

/**
 *
 * @Author 鳄鱼杆
 * @Description BeanUtils封装
 */
public class BeanCopyUtil {

    private BeanCopyUtil(){}

    public static <V> V copyBean(Object source,Class<V> clazz){
        V result = null;

        try {
            result = clazz.newInstance();
            BeanUtils.copyProperties(source,result);
        } catch (Exception e) {
//            反射实例化失败
            e.printStackTrace();
        }

        return result;
    }


    public static <T,V> List<V> copyBeanList(List<T> list , Class<V> clazz){

        return list.stream()
                .map(o -> copyBean(o, clazz))
                .collect(Collectors.toList());
    }
}
